﻿<template>
  <a-modal
    title="编辑明细费用上传通知输出"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item label="机构系统跟踪号机构系统跟踪号，和拉取待结算时候返回的 org_trace_no 对应 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入机构系统跟踪号机构系统跟踪号，和拉取待结算时候返回的 org_trace_no 对应 " v-decorator="['orgTraceNo']" />
        </a-form-item>
        <a-form-item label="上传“移动支付中心”成功后，“移动支付中心”响应出参（解密过的 json 参数）必填，解密后的移动支付中心响应参数，需要未修改的原封不动的透传回来 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入上传“移动支付中心”成功后，“移动支付中心”响应出参（解密过的 json 参数）必填，解密后的移动支付中心响应参数，需要未修改的原封不动的透传回来 " v-decorator="['mpcResponse']" />
        </a-form-item>
        <a-form-item label="移动支付中心的支付订单号必填 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入移动支付中心的支付订单号必填 " v-decorator="['payOrdId']" />
        </a-form-item>
        <a-form-item label="移动支付中心的支付 token必填 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入移动支付中心的支付 token必填 " v-decorator="['payToken']" />
        </a-form-item>
        <a-form-item label="移动支付中心返回的收银台地址必填 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入移动支付中心返回的收银台地址必填 " v-decorator="['cashierUrl']" />
        </a-form-item>
        <a-form-item v-show="false"><a-input v-decorator="['iD']" /></a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import {
    NitfOrg002bOutputEdit
  } from '@/api/modular/main/NitfOrg002bOutputManage'
  export default {
    data () {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
        },
        visible: false,
        confirmLoading: false,
        form: this.$form.createForm(this)
      }
    },
    methods: {
      // 初始化方法
      edit (record) {
        this.visible = true
        setTimeout(() => {
          this.form.setFieldsValue(
            {
              iD: record.iD,
              orgTraceNo: record.orgTraceNo,
              mpcResponse: record.mpcResponse,
              payOrdId: record.payOrdId,
              payToken: record.payToken,
              cashierUrl: record.cashierUrl
            }
          )
        }, 100)
      },
      handleSubmit () {
        const { form: { validateFields } } = this
        this.confirmLoading = true
        validateFields((errors, values) => {
          if (!errors) {
            for (const key in values) {
              if (typeof (values[key]) === 'object') {
                values[key] = JSON.stringify(values[key])
              }
            }
            NitfOrg002bOutputEdit(values).then((res) => {
              if (res.success) {
                this.$message.success('编辑成功')
                this.confirmLoading = false
                this.$emit('ok', values)
                this.handleCancel()
              } else {
                this.$message.error('编辑失败：' + JSON.stringify(res.message))
              }
            }).finally((res) => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      handleCancel () {
        this.form.resetFields()
        this.visible = false
      }
    }
  }
</script>
